$import( "SmitearWebGL.Objects.Parser.Collada.DaeEntity" );
$import( "SmitearWebGL.Objects.Parser.Collada.DaeInput" );

SmitearWebGL.Objects.Parser.Collada.DaeVertexWeights = SmitearWebGL.Objects.Parser.Collada.DaeEntity.extend(
{
	/******** constructor ********/

	init : function( document, node )
	{
		this.count = 0;
		this.inputs = null;
		this.v = null;
		this.vcounts = null;

		this._super( document, node );
		this._registClass( "SmitearWebGL.Objects.Parser.Collada.DaeVertexWeights" );
	}
	,
	read : function( node )
	{
		$THROW( node.localName == SmitearWebGL.Objects.Parser.Collada.Const.DAE_WEIGHTS_ELEMENT,
		"not a <" + SmitearWebGL.Objects.Parser.Collada.Const.DAE_WEIGHTS_ELEMENT + "> element!" );

		this.inputs = [];

		this._super( node );

		this.count = this.getAttributeAsInt( node, SmitearWebGL.Objects.Parser.Collada.Const.DAE_COUNT_ATTRIBUTE );

		$LOG( " => reading vertex_weights" );

		// require 2 or more <input> elements
		var inputList = this.getNodeList( node, SmitearWebGL.Objects.Parser.Collada.Const.DAE_INPUT_ELEMENT );
		$THROW( inputList.length >= 2, "<joints> requires at least 2 <input> elements!" );

		// parse <input> elements
		for( var i = 0; i < inputList.length; i++ )
		{
			var input = new SmitearWebGL.Objects.Parser.Collada.DaeInput(this.document, inputList[i]);
			this.inputs.push( input);
		}

		this.v = [];
		this.vcounts = [];

		var vNode = this.getNode(node, SmitearWebGL.Objects.Parser.Collada.Const.DAE_VERTEX_ELEMENT);
		var vcountNode = this.getNode(node, SmitearWebGL.Objects.Parser.Collada.Const.DAE_VERTEXCOUNT_ELEMENT);

		if( !vNode || !vcountNode )
			return;

		// Describes which bones and attributes are associated with each
		// vertex. An index of -1 into the array of joints refers to the bind shape.
		// Weights should be normalized before use.
		this.v = this.getInts( vNode );

		// Describes the number of bones associated with each vertex.
		this.vcounts = this.getInts( vcountNode );
	}
}
);